home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
276-300
/
291
/
keyboard
/
rawdemo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-14
|
5KB
|
150 lines
/* RawDemo.c
by Fabbian G. Dufoe, III
This is a public domain program. You may use it any way you want.
This program demonstrates the use of the OpenReadConsole(), ReadKey(),
and CloseReadConsole() functions in Keyboard.c
*/
#include "keyboard.h"
#define VERSION 34L
struct IntuiText IText1 =
{
1, 0, JAM1, 4, 12,
NULL,
"Type some keys.",
NULL
};
struct NewWindow NewWindow =
{
0, 10, /* SHORT LeftEdge, TopEdge, */
550, 190, /* SHORT Width, Height, */
0, 1, /* UBYTE DetailPen, BlockPen, */
CLOSEWINDOW | RAWKEY | MOUSEBUTTONS,
/* ULONG IDCMPFlags, */
WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | WINDOWSIZING |
ACTIVATE | SMART_REFRESH,
/* ULONG Flags, */
NULL, /* struct Gadget *FirstGadget, */
NULL, /* struct Image *CheckMark, */
"RawDemo",
/* UBYTE *Title, */
NULL, /* struct Screen *Screen, */
NULL, /* struct BitMap *BitMap, */
10, 10, /* SHORT MinWidth, MinHeight, */
640, 400, /* USHORT MaxWidth, MaxHeight, */
WBENCHSCREEN /* USHORT Type, */
};
void
main()
{
int error = 30;
struct IntuiMessage *IMessage;
ULONG IMessageClass;
extern struct IntuitionBase *IntuitionBase;
void PrintKey(struct IntuiMessage *);
struct Window *Window;
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", VERSION);
if (IntuitionBase)
{
if (OpenReadConsole() == 0)
{
if (Window = (struct Window *)OpenWindow(&NewWindow))
{
PrintIText(Window->RPort, &IText1, 0, 0);
do
{
Wait(1<<Window->UserPort->mp_SigBit);
while ((IMessage = (struct IntuiMessage *)
GetMsg(Window->UserPort)) != NULL)
{
switch (IMessage->Class)
{
case CLOSEWINDOW:
break;
case RAWKEY:
PrintKey(IMessage);
break;
case MOUSEBUTTONS:
printf("Mouse X: %d\tY: %d\n",
IMessage->MouseX,
IMessage->MouseY);
break;
}
IMessageClass = IMessage->Class;
ReplyMsg(IMessage);
}
}
while (IMessageClass != CLOSEWINDOW);
CloseWindow(Window);
}
else
printf("OpenWindow() failed.\n");
CloseReadConsole();
}
else
printf("OpenReadConsole() failed.\n");
CloseLibrary(IntuitionBase);
}
else
printf("OpenLibrary() failed for intuition.library.\n");
exit(error);
}
void
PrintKey(struct IntuiMessage *IMessage)
{
char Key;
unsigned short int KeyID;
Key = ReadKey(IMessage, &KeyID, NULL);
if (Key == -1 || Key == -2)
return;
if (Key != 0)
printf("Key: %c\n", Key);
else
{
switch (KeyID)
{
case K_UP: printf("K_UP\n"); break;
case K_DOWN: printf("K_DOWN\n"); break;
case K_RIGHT: printf("K_RIGHT\n"); break;
case K_LEFT: printf("K_LEFT\n"); break;
case K_S_UP: printf("K_S_UP\n"); break;
case K_S_DOWN: printf("K_S_DOWN\n"); break;
case K_S_RIGHT: printf("K_S_RIGHT\n"); break;
case K_S_LEFT: printf("K_S_LEFT\n"); break;
case K_HELP: printf("K_HELP\n"); break;
case K_F1: printf("K_F1\n"); break;
case K_F2: printf("K_F2\n"); break;
case K_F3: printf("K_F3\n"); break;
case K_F4: printf("K_F4\n"); break;
case K_F5: printf("K_F5\n"); break;
case K_F6: printf("K_F6\n"); break;
case K_F7: printf("K_F7\n"); break;
case K_F8: printf("K_F8\n"); break;
case K_F9: printf("K_F9\n"); break;
case K_F10: printf("K_F10\n"); break;
case K_S_F1: printf("K_S_F1\n"); break;
case K_S_F2: printf("K_S_F2\n"); break;
case K_S_F3: printf("K_S_F3\n"); break;
case K_S_F4: printf("K_S_F4\n"); break;
case K_S_F5: printf("K_S_F5\n"); break;
case K_S_F6: printf("K_S_F6\n"); break;
case K_S_F7: printf("K_S_F7\n"); break;
case K_S_F8: printf("K_S_F8\n"); break;
case K_S_F9: printf("K_S_F9\n"); break;
case K_S_F10: printf("K_S_F10\n"); break;
}
}
}